﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcVehicleInsurance.Models
{
    public class AccountLoginModels
    {
        private DataClassesVehicleDataContext dc = new DataClassesVehicleDataContext();
       
        public CustomerRecord DangnhapAdmin(string Username, string Password)
        {
            CustomerRecord a = new CustomerRecord();
            try
            {
                a = this.dc.CustomerRecords.Single(ac => ac.customerUsername.Equals(Username) && ac.customerPassword.Equals(Password));

            }
            catch
            {
                a = null;
            }

            return a;
        }
        public bool ThemAccount(string Username, string Password, string fullname, string gender, string Address, string Email)
        {
            bool kq = true;

            try
            {
                Account ac = new Account();
                ac.Acc_Username = Username;
                ac.Acc_Password = Password;
                ac.Acc_FullName = fullname;
                ac.Acc_Gender = gender;

                ac.Acc_Address = Address;
                ac.Acc_Email = Email;

                this.dc.Accounts.InsertOnSubmit(ac);
                this.dc.SubmitChanges();

            }
            catch
            {
                kq = false;

            }
            return kq;

        }

        public List<Account> Danhsach()
        {
            return this.dc.Accounts.ToList();
        }

        public bool DangNhap(string Username, string Password)
        {
            bool kq = true;
            try
            {
                kq = this.dc.CustomerRecords.Where(ac => ac.customerUsername.Equals(Username)
                && ac.customerPassword.Equals(Password)).Count() == 1;
            }
            catch
            {
                kq = false;
            }
            return kq;
        }

        public Account Thongtin(string Username)
        {
            return this.dc.Accounts.Single(ac => ac.Acc_Username.Equals(Username));
        }

        public CustomerRecord LoginUser(string Username, string Password)
        {
            CustomerRecord c = new CustomerRecord();
            try
            {
                c = this.dc.CustomerRecords.Single(cs => cs.customerUsername.Equals(Username) && cs.customerPassword.Equals(Password)); 
            }
            catch
            {
                c = null;
            }
            return c;
            
        }


    }
}